package com.wx.mall.sys.controller;


import com.wx.mall.common.ResultVo;
import com.wx.mall.sys.entity.MessageRemind;
import com.wx.mall.sys.service.IMessageRemindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lixuqiang
 * @since 2020-03-18
 */
@RestController
@RequestMapping("/message-remind")
@Api(tags = "消息提醒接口")
@Slf4j
public class MessageRemindController {

    @Autowired
    private IMessageRemindService iMessageRemindService;

    @ApiOperation("查询消息提醒")
    @GetMapping("/find")
    public String find(){
        return new ResultVo(ResultVo.ErrorCode.SUCCESS,"", iMessageRemindService.find(new MessageRemind())).toString();
    }

    @ApiOperation("查询消息提醒")
    @GetMapping("/get")
    public String get(@ApiParam("消息提醒id")String id){
        return new ResultVo(ResultVo.ErrorCode.SUCCESS,"", iMessageRemindService.get(id)).toString();
    }

    @ApiOperation("查询消息提醒")
    @PostMapping("/updateSend")
    public String updateSend(@ApiParam("消息提醒id")String id,@ApiParam("是否发送")String isSend){
        MessageRemind messageRemind = iMessageRemindService.get(id);
        messageRemind.setIsSend(isSend);
        iMessageRemindService.update(messageRemind);
        return new ResultVo(ResultVo.ErrorCode.SUCCESS,"更新成功", "").toString();
    }

    @ApiOperation("保存和更新消息提醒")
    @PostMapping("/form")
    public String form(@ApiParam("消息提醒对象") String id,
                       @ApiParam("消息类型") String messageType,
                       @ApiParam("邮件标题") String emailTitle,
                       @ApiParam("内容模板") String content,
                       @ApiParam("用户名") String labelUsername,
                       @ApiParam("订单号") String labelOrderId,
                       @ApiParam("订单金额") String labelTotal,
                       @ApiParam("配送方式") String labelShippingType,
                       @ApiParam("收货人姓名") String labelShippingName,
                       @ApiParam("收货人地址") String labelShippingAddr,
                       @ApiParam("收货人邮编") String labelShippingZip,
                       @ApiParam("收货人电话") String labelShippingPhone,
                       @ApiParam("收货人手机") String labelShippingCell,
                       @ApiParam("收货人Email") String labelShippingEmail,
                       @ApiParam("商城名称") String labelSiteName,
                       @ApiParam("备注") String labelMemo){
        MessageRemind messageRemind = new MessageRemind();
        messageRemind.setMessageType(messageType);
        messageRemind.setEmailTitle(emailTitle);
        messageRemind.setContent(content);
        messageRemind.setLabelUsername(labelUsername);
        messageRemind.setLabelOrderId(labelOrderId);
        messageRemind.setLabelTotal(labelTotal);
        messageRemind.setLabelShippingType(labelShippingType);
        messageRemind.setLabelShippingName(labelShippingName);
        messageRemind.setLabelShippingAddr(labelShippingAddr);
        messageRemind.setLabelShippingZip(labelShippingZip);
        messageRemind.setLabelShippingPhone(labelShippingPhone);
        messageRemind.setLabelShippingCell(labelShippingCell);
        messageRemind.setLabelShippingEmail(labelShippingEmail);
        messageRemind.setLabelSiteName(labelSiteName);
        messageRemind.setLabelMemo(labelMemo);
        if(!StringUtils.isEmpty(id)){
            messageRemind.setId(Integer.valueOf(id));
            iMessageRemindService.update(messageRemind);
        }else{
            iMessageRemindService.save2(messageRemind);
        }
        return new ResultVo(ResultVo.ErrorCode.SUCCESS,"提交成功", "").toString();
    }


}

